import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { HttpCom } from '../net/HttpCom';
import { StoreItem } from '../StoreItem';
const { ccclass, property } = _decorator;

@ccclass('StorePage')
export class StorePage extends Component {

    @property(Node)
    itemContent: Node = null;
    @property(Prefab)
    itemPre: Prefab = null;

    protected onLoad(): void {
        
    }

    onEnable(): void {
        console.log("获取商品列表")
        HttpCom.list((resp)=>{
            this.itemContent.removeAllChildren();
            resp.rows.forEach((e,i)=>{
                let item = instantiate(this.itemPre);
                let com = item.getComponent(StoreItem);
                com.initView(e.value,e.price,e.id);
                this.itemContent.addChild(item);
                
            })
        });
    }

    start() {
        //console.log("获取商品列表")
        //HttpCom.list();
    }

    update(deltaTime: number) {
        
    }
}


